package chat.controller;

import chat.service.IChatService;
import common.model.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import javax.websocket.server.PathParam;

@RequestMapping("/chat")
@RestController
public class ChatController {

    @Autowired
    IChatService chatService;

    @GetMapping("/searchOnlineAdmin")
    public Result searchOnlineAdmin() {
        return chatService.getOnlineAdminId();
    }

    @GetMapping("/getUserChatHistory")
    public Result getUserChatHistory(@PathParam("userId")Long userId) {
        return chatService.getHistoryMessage(userId);
    }

    @GetMapping("/getChatHistory")
    public Result getChatHistory(@RequestHeader("uid")Long userId) {
        System.out.println(userId);
        return chatService.getHistoryMessage(userId);
    }
    //关闭聊天室
    @PostMapping("/close")
    public Result close(@RequestParam("userId")Long userId) {
        return chatService.closeChatRoom(userId);
    }
}
